package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.pojo.dto.StudentUpdateStatusDto;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.Student;
import com.ruoyi.system.pojo.dto.StudentFromClassDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.pojo.domain.StudentManage;
import com.ruoyi.system.service.IStudentManageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学生管理Controller
 * 
 * @author sxb
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/studentManage")
public class StudentManageController extends BaseController
{
    @Autowired
    private IStudentManageService studentManageService;

    //根据班级id查询学生信息
    @GetMapping("/getStudentFromClass/{classId}")
    public AjaxResult getStudentFromclass(@PathVariable Long classId){
        List<StudentManage>  studentManages = studentManageService.getAllStudents();
        return AjaxResult.success(studentManages);
    }



    /**
     * 查询学生管理列表
     */
//    @RequiresPermissions("system:studentManage:list")
    @GetMapping("/list")
    public TableDataInfo list(StudentManage studentManage)
    {
        startPage();
        List<StudentManage> list = studentManageService.selectStudentManageList(studentManage);
        return getDataTable(list);
    }

    /**
     * 导出学生管理列表
     */
    @RequiresPermissions("system:studentManage:export")
    @Log(title = "学生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentManage studentManage)
    {
        List<StudentManage> list = studentManageService.selectStudentManageList(studentManage);
        ExcelUtil<StudentManage> util = new ExcelUtil<StudentManage>(StudentManage.class);
        util.exportExcel(response, list, "学生管理数据");
    }

    /**
     * 获取学生管理详细信息
     */
    @RequiresPermissions("system:studentManage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studentManageService.selectStudentManageById(id));
    }

    /**
     * 新增学生管理
     */
    @RequiresPermissions("system:studentManage:add")
    @Log(title = "学生管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentManage studentManage)
    {
        return toAjax(studentManageService.insertStudentManage(studentManage));
    }

    /**
     * 修改学生管理
     */
    @RequiresPermissions("system:studentManage:edit")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentManage studentManage)
    {
        return toAjax(studentManageService.updateStudentManage(studentManage));
    }

    /**
     * 修改学生状态
     */
    @PutMapping("/updateStatus")
    public AjaxResult updateStudentStatus(@RequestBody StudentUpdateStatusDto studentUpdateStatusDto)
    {
        return toAjax(studentManageService.updateStudentStatus(studentUpdateStatusDto));
    }

    /**
     * 删除学生管理
     */
    @RequiresPermissions("system:studentManage:remove")
    @Log(title = "学生管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studentManageService.deleteStudentManageByIds(ids));
    }


    /**
     * 远程服务新增学生管理
     */
    @Log(title = "学生管理", businessType = BusinessType.INSERT)
    @PostMapping("/remoteInsert")
    public R remoteInsert(@RequestBody Student student)
    {
        studentManageService.remoteInsertStudentManage(student);
        return R.ok();
    }


}
